package com.cat.dataStructure02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/min-stack/
 * @create 2025/10/24 18:28
 * @since JDK17
 */

class MinStack {
    static int N = ((int) (3e4 + 10)), top;
    static int[] s1 = new int[N], s2 = new int[N];
    public MinStack() {
        top = 0;
    }

    public void push(int val) {
        if (top == 0 || val < s2[top - 1]) {
            s2[top] = val;
        } else {
            s2[top] = s2[top - 1];
        }
        s1[top++] = val;
    }

    public void pop() {
        top--;
    }

    public int top() {
        return s1[top - 1];
    }

    public int getMin() {
        return s2[top - 1];
    }
}
